package com.faxe.educar.ws.controller;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.faxe.educar.ws.bo.ServiceBO;
import com.faxe.educar.ws.to.ServiceTO;
import com.faxe.educar.ws.utils.JsonObject;

@Controller
@RequestMapping("/search")
public class SearchController {

	private ServiceBO mgrService;
	
	
	@RequestMapping(value="/filter", method = RequestMethod.GET)
	public @ResponseBody JsonObject filterSearch(HttpServletRequest request, HttpServletResponse response) {
		
		String category = request.getParameter("category");
		String subcategory = request.getParameter("subcategory");
		String state = request.getParameter("state");
		String city = request.getParameter("city");
		String query = request.getParameter("query");
		
		List<ServiceTO> services = mgrService.getFilterList(category, subcategory, state, city, query);
		
		JsonObject jResp = new JsonObject();
		jResp.setMessage("OK");
		jResp.setData(services);
		jResp.setContentType("json");
		
		response.setContentType("json");
		
		return jResp;
	}
	
	@Autowired
	public void setServiceBO(ServiceBO serviceBO){
		this.mgrService = serviceBO;
	}
	
	
	
}
